package com.paotui.controller;

import cn.hutool.json.JSONUtil;
import com.paotui.common.R;
import com.paotui.pojo.Users;
import com.paotui.service.impl.UsersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/users/add")
public class UsersAddController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Users users = new Users();
        users.setUsersName(request.getParameter("UsersName"));
        users.setUsersTelephone(request.getParameter("UsersTelephone"));
        users.setUsersEmail(request.getParameter("UsersEmail"));
        users.setUsersPassword(request.getParameter("UsersPassword"));
        //users.setUsersStatus(Integer.parseInt(request.getParameter("UsersStatus")));
        UsersServiceImpl usersService = new UsersServiceImpl();
        usersService.save(users);
        usersService.getSqlSession().close();
        R r = R.success("添加成功");
        PrintWriter out  = response.getWriter();
        out.write(JSONUtil.toJsonStr(r));

    }
}
